﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>登录</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    <link href="@Url.Content("~/Scripts/Toastr/toastr.min.css")" rel="stylesheet" />

    <!-- jQuery -->
    @Scripts.Render("~/bundles/jquery")
    <script src="@Url.Content("~/bower_components/jquery/dist/jquery.min.js")"></script>
    @Scripts.Render("~/bundles/bootstrap")
    @Scripts.Render("~/bundles/common")

</head>
<body>
    @Html.Partial("_Loading")
    <div class="container">
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                <div class="text-center" style="margin-top:25%;">
                    <h3 style="margin-top:-5px;">权限管理系统</h3>
                </div>
                <div class="login-panel panel panel-default" style="margin-top:10%;">
                    <div class="panel-body">
                        <form id="loginForm" role="form" onsubmit="login(); return false;">
                            <fieldset>
                                <div class="form-group">
                                    <input id="Username" class="form-control" placeholder="用户名" name="Username" type="text" autofocus>
                                </div>
                                <div class="form-group">
                                    <input id="Password" class="form-control" placeholder="密码" name="Password" type="password" value="">
                                </div>
                                <button type="submit" class="btn btn-lg btn-success btn-block">登录</button>
                            </fieldset>
                        </form>
                    </div>
                </div>
                <div class="text-center" style="margin-top:10%">
                    <span>2017 孙宇个人开发项目</span>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        var loginurl = "@Url.Action("Login")";
        var indexurl = '@Url.Action("Index", "Home")';
        var warningurl = "@Url.Action("Warning","Home")";
        var loginerror = '@("Landing failed! Please contact the system administrator!")';
        function login() {
            loading.start();
            var data = {};
            $("#loginForm").serializeArray().map(function (x) { data[x.name] = x.value; });
            $.ajax({
                type: "POST",
                url: loginurl,
                data: data,
                dataType: "json",
                success: function (data) {
                    if (data.IsSuccess) {
                            window.location.href = indexurl;
                    } else {
                        toastr.warning(data.Message);
                        loading.end();
                    }
                },
                error: function (result, textStatus) {
                    toastr.warning(loginerror);
                    loading.end();
                }
            });
        }
    </script>
</body>
</html>